<template>
	<div class="count">
		<h1>当前求和为：{{sum}}</h1>
		<h3>当前求和放大10倍后：{{$store.getters.bigSum}}</h3>
		<h3>学校名称：{{school}}</h3>
		<h3>学校地址：{{address}}</h3>
		<h3>所学学科：{{subject}}</h3>
		<select v-model.number="n">
			<option value="1">1</option>
			<option value="2">2</option>
			<option value="3">3</option>
		</select>
		<button @click="increment">+</button>
		<button @click="decrement">-</button>
		<button @click="incrementOdd">当前求和为奇数再+</button>
		<button @click="incrementWait">等一等再+</button>
		<button @click="incrementServer">问问服务器再+</button>
	</div>
</template>

<script>
	export default {
		name:'Count',
		data() {
			return {
				n:1 //用户选择的数字
			}
		},
		computed:{
			sum(){
				return this.$store.state.sum
			},
			school(){
				return this.$store.state.school
			},
			address(){
				return this.$store.state.address
			},
			subject(){
				return this.$store.state.subject
			}
		},
		methods:{
			//加
			increment(){
				//联系对应的mutation函数，触发JIA（即：直接联系厨师）
				this.$store.commit('JIA',this.n)
			},
			//减
			decrement(){
				//联系对应的mutation函数，触发JIAN（即：直接联系厨师）
				this.$store.commit('JIAN',this.n)
			},
			//奇数再加
			incrementOdd(){
				this.$store.dispatch('jiaOdd',this.n)
			},
			//等等再加
			incrementWait(){
				this.$store.dispatch('jiaWait',this.n)
			},
			//联系服务器再加
			incrementServer(){
				this.$store.dispatch('jiaServer')
			}
		},
	}
</script>

<style scoped>
	.count{
		background-color: skyblue;
		padding: 20px;
	}
	button{
		margin-left: 10px;
	}
</style>